<template>
  <div class="user">

    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      > 
        <el-form-item label="">
          <el-input
            v-model="formInline.title"
            placeholder="请输入商品名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="product-content">
      
        <div class="table-wrap">
          <el-table
            size="small"
            :data="tableData"
            border
            style="width: 100%"
            v-loading="loading"
          >
            <el-table-column prop="product_name" label="拼团商品" width="200"></el-table-column>
            <el-table-column
              prop="supplier[0].name"
              label="店铺"
              width="200"
            ></el-table-column>
            <el-table-column
              prop="limit_num"
              label="限购数量"
              width="80"
            ></el-table-column>
            <el-table-column
              prop="stock"
              label="库存总量"
              width="100"
            ></el-table-column>
            <el-table-column
              prop="sales_initial"
              label="虚拟销量"
              width="100"
            ></el-table-column>
            <el-table-column
              prop="total_sales"
              label="累计销量"
              width="100"
            ></el-table-column>
            <el-table-column
              prop="join_num"
              label="参与人数"
              width="100"
            ></el-table-column>
            <el-table-column
              prop="status_text"
              label="状态"
              width="70"
            ></el-table-column>
            <el-table-column
              prop="create_time"
              label="创建时间"
              width="150"
            ></el-table-column>
            <el-table-column fixed="right" label="操作" width="120">
              <template slot-scope="scope">
                <el-button
                  @click="editClick(scope.row)"
                  type="text"
                  size="small"
                  >详情</el-button
                >
                <el-button
                  @click="deleteClick(scope.row)"
                  type="text"
                  size="small"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog title="设置推荐" :visible.sync="visible" @close="visible=false" :close-on-click-modal="true" :close-on-press-escape="false" width="600px">
      <div class="dialog-height">
        <Recommend></Recommend>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import AssembleApi from "@/api/assemble.js";
import Recommend from "./PrdRecommend.vue";
export default {
  components: { Recommend },
  data() {
    return {
      visible: false,
      /*是否打开选择商品*/
      isproduct: false,
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      formInline:{
        title:''
      }
    };
  },
  props: {
    activity_id: Number,
  },
  watch: {
    activity_id: function (val) {
      if( val ){
        this.getTableList();
      }
      
    },
  },
  created() {
    /*获取列表*/
    if( this.activity_id ){
      this.getTableList();
    }
    
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      this.curPage = val;
      this.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.assemble_activity_id = this.activity_id;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      self.loading = true;
      AssembleApi.listProduct(Params, true)
        .then((data) => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    /* 审核*/
    toAudit(id) {
      this.$router.push({
        path: "/plus/assemble/index",
        query: {
          type: "audit",
          id: id,
        },
      });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    handleClose() {
      this.prodVisible = false;
    },
    recommendClick(row) {
      let assemble_product_id = row.assemble_product_id;
      this.visible = true;
    },
    /*场次管理*/
    editClick(row) {
      let assemble_product_id = row.assemble_product_id;
      this.$router.push({
        path: "/plus/assemble/active/editprd",
        query: {
          assemble_product_id: assemble_product_id,
        },
      });
    },
    //选择商品
    chooseProduct(row) {
      let assemble_activity_id = row.assemble_activity_id;
      this.activity_id = assemble_activity_id;
      let arr = [];
      let list = [];
      list.forEach((item) => {
        arr.push(item.product_id);
      });
      this.excludeIds = arr;
      this.isproduct = true;
    },
    /*关闭弹窗*/
    closeDialogFunc(e) {
      let self = this;
      self.isproduct = false;
      if (e.type == "success") {
        let product = e.params;
        // console.log(product);
        let product_id = product.product_id;
        this.$router.push({
          path: "/plus/assemble/active/addprd",
          query: {
            activity_id: this.activity_id,
            product_id: product_id,
          },
        });
      }
    },
    /*删除*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm("删除操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          AssembleApi.delProduct(
            {
              assemble_product_id: row.assemble_product_id,
            },
            true
          )
            .then((data) => {
              if (data.code == 1) {
                self.$message({
                  message: "拼团商品删除成功",
                  type: "success",
                });
                //刷新页面
                self.getTableList();
              } else {
                self.$message.error("错了哦，这是一条错误消息");
              }
            })
            .catch((error) => {});
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
.fbb {
  border-bottom: 1px solid #409eff;
  color: #409eff;
  padding-bottom: 0px;
  width: 7px;
}
.dialog-height {
  height: 60vh;
}
</style>
